import { request } from '@/utils/request'
import type {
  KnowledgeParams,
  KnowledgePage,
  PageParams,
  DoctorPage,
  FollowType,
  TopDep,
  Image,
  ConsultOrderPreParmas,
  ConsultOrderPreData,
  PartialConsult
} from '@/types/consult'

// 获取文章的列表
const getKnowledgeList = (params: KnowledgeParams) => {
  return request<KnowledgePage>('/patient/home/knowledge', 'get', params)
}
// 获取推荐医生的列表
const getDoctorList = (params: PageParams) => {
  return request<DoctorPage>('/home/page/doc', 'get', params)
}

// 关注和取消关注
const followDoctor = (id: string, type: FollowType = 'doc') => {
  return request('/like', 'post', { id, type })
}

// 获取科室数据
const getAllDep = () => request<TopDep[]>('/dep/all', 'GET')

// 上传图片
const uploadImage = (file: File) => {
  // 需要将file转化为FormData的格式
  const fd = new FormData()
  fd.append('file', file)
  return request<Image>('/upload', 'POST', fd)
}

// 获取支付的信息
const getPayInfo = (params: ConsultOrderPreParmas) => {
  return request<ConsultOrderPreData>(
    '/patient/consult/order/pre',
    'GET',
    params
  )
}

// 生成订单的id
const creatConsultOrder = (data: PartialConsult) => {
  return request<{ id: string }>('/patient/consult/order', 'POST', data)
}

// 获取支付宝的地址
const getConsultOrderPay = (data: {
  paymentMethod: number
  orderId: string
  payCallback: string
}) => {
  return request<{ payUrl: string }>('/patient/consult/pay', 'POST', data)
}
export {
  getKnowledgeList,
  getDoctorList,
  followDoctor,
  getAllDep,
  uploadImage,
  getPayInfo,
  creatConsultOrder,
  getConsultOrderPay
}
